﻿using LBSoft.Business.NewDAL;
using LBSoft.Business;
using LBSoft.Common.DotNetCode;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimpleServiceTest
{
    public partial class Form1 : Form
    {
        CommonDal com = new CommonDal();
        Common_Dal systemidao = new Common_Dal();
        LogHelper log = new LogHelper();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ExecIntervalSecondFunc();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ExecIntervalMinuteFunc();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ExecTimeSpotFunc();
        }

        #region 执行业务代码

        /// <summary>
        /// ExecIntervalSecondFunc
        /// </summary>
        private void ExecIntervalSecondFunc()
        {
            //数据库操作
            DataTable dt = systemidao.GetDataTableBySQL(new StringBuilder($@"SELECT * FROM dbo.T_Project"));
            log.WriteLog(JsonConvert.SerializeObject(dt));

            log.WriteLog("间隔执行（秒）");

            ShowMessage(JsonConvert.SerializeObject(dt));
            ShowMessage("间隔执行（秒）");
        }

        /// <summary>
        /// ExecIntervalMinuteFunc
        /// </summary>
        private void ExecIntervalMinuteFunc()
        {
            log.WriteLog("间隔执行（分）");

            ShowMessage("间隔执行（分）");
        }

        /// <summary>
        /// ExecTimeSpotFunc
        /// </summary>
        private void ExecTimeSpotFunc()
        {
            log.WriteLog("定点执行（时间点）");

            ShowMessage("定点执行（时间点）");
        }

        #endregion

        private void ShowMessage(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                richTextBox1.Text += message + "\r\n";
            }
        }

    }
}
